package com.health.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.health.domain.vo.Result;
import com.health.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author ghy
 * @version 1.0
 * @since 2025-06-23 20:56
 */
@Service
public class CodeServiceImpl implements CodeService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public Result<String> send4Login(String telephone) {
        // 生成验证码
        String validateCode = RandomUtil.randomNumbers(4);
        // 将验证码存储Redis
        stringRedisTemplate.opsForValue().set("member_login_code_" + telephone, validateCode, 5, TimeUnit.MINUTES);
        // TODO 调用短信接口发送验证码
        System.out.println("验证码：" + validateCode);
        return Result.success("发送成功", validateCode);
    }

    @Override
    public Result<String> send4Order(String telephone) {
        // 生成验证码
        String validateCode = RandomUtil.randomNumbers(4);
        // 将验证码存储Redis
        stringRedisTemplate.opsForValue().set("member_order_code_" + telephone, validateCode, 10, TimeUnit.MINUTES);
        // TODO 调用短信接口发送验证码
        System.out.println("验证码：" + validateCode);
        return Result.success("发送成功", validateCode);
    }

}
